package com.example.service;


import com.example.dao.MessageDao;
import com.example.pojo.Message;
import com.example.pojo.Params;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MessageService {

    @Resource
    private MessageDao messageDao;


    public void add(Message message) {
        messageDao.insertSelective(message);
    }

    public void update(Message message) {
        messageDao.updateByPrimaryKeySelective(message);
    }

    public PageInfo<Message> findBySearch(Params params) {
        // 开启分页查询
        PageHelper.startPage(params.getPageNum(), params.getPageSize());
        // 接下来的查询会自动按照当前开启的分页设置来查询
        List<Message> list = messageDao.findBySearch(params);
        return PageInfo.of(list);
    }

    public void delete(Integer id) {  messageDao.deleteByPrimaryKey(id);
    }

    public List<Message> findAll() {
        return messageDao.selectAll();
    }
}
